package com.woniuxy.control;/*
 * @Author: Tiangle
 * @Date:   {DATE}
 * @TIME:   {TIME}
 * @Project_Name: {PROJECT_NAME}
 * @Package_Name: {PACKAGE_NAME}
 */

import com.woniuxy.commons.JDKProxy;
import com.woniuxy.service.AccountService;
import com.woniuxy.service.impl.AccountServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/t")
public class AccountServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AccountService proxy = new JDKProxy<AccountService>().getProxy(new AccountServiceImpl());
        String source = req.getParameter("source");
        String target = req.getParameter("target");
        String money = req.getParameter("money");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        boolean transfer = proxy.transfer(source, target, Double.valueOf(money));
        if (transfer){
            resp.getWriter().print("<h1>转账成功<h1>");
        }else{
            resp.getWriter().print("<h1>转账失败<h1>");
        }
    }
}
